﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SportsStore.Domain.Abstract;
using SportsStore.Domain.Entities;

namespace SportsStore.Domain.Concrete
{
    public class EFCategoryRepository:ICategoryRepository
    {
        private KeLianEntities context = new KeLianEntities(); 

        public IQueryable<Category> Categories
        {
            get { return context.Categories; }
        }

        public void SaveCategory(Category category)
        {
            if (category.Id == 0)
                context.Categories.AddObject(category);
            else
            {
                Category modifyingCategory = Categories.FirstOrDefault(c => c.Id == category.Id);
                modifyingCategory.Name = category.Name;
                modifyingCategory.Ranking = category.Ranking;
                modifyingCategory.Description = category.Description;
            }
            context.SaveChanges();
        }

        public void DeleteCategory(Category category)
        {
            context.Categories.DeleteObject(category);
            context.SaveChanges();
        }
    }
}
